<?php
namespace Admin\Controller;
use Think\Controller;
class ClubMemberController extends Controller {
   public function clubmlist(){
        $memberModel=M('club_member'); //实例化模型对象 user 表名
		$member=$memberModel->order('club_member_id desc')->select(); //查询
		$this->member=$member; //volist name
		// dump ($users); 
		$this->display();
    }
    public function delmember(){
         // dump($_GET);
        $videoModel=M('club_member');
        $vid=$_GET['vid'];
        //var_dump($uid);
        $res=$videoModel->where("club_member_id=$vid")->find();
        //var_dump($res);
        $photoPath=realpath("./Public/Uploads/videophoto".$res['club_member_picture']);
        unlink($photoPath);
        if ($videoModel->where("club_member_id=$vid")->delete()) {
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }
    public function clubmadd(){
        $this->display();
    }
    public function clubmaddd(){
        if ($_FILES['files']['error']==0) {
                $loginfo=$this->MyUpload();
                $pname=$loginfo['file']['savename'];
                dump ($loginfo);
                

            }
            else{
                $pname="defalt.jpg";
            }
        $videos = D('club_member'); 
 
        if ($videos->create()) {
          
            $data['club_member_name'] = I('post.club_member_name');
            $data['club_member_sex'] = I('post.club_member_sex');
            $data['club_member_phonenumbe'] = I('post.club_member_phonenumbe');
            $data['club_member_age'] = I('post.club_member_age');
            $data['club_member_clubid'] =S('club_id');
            $data['club_member_date']=date('Y-m-d H:i:s');
            $data['club_member_picture']=$pname;
            
            if (false !== $videos->add($data)){
                 echo $videos->getLastSql();
                 // exit();
                $this->success('添加成功！', 'clubmlist');
            } else {         $this->error('数据错误');           }
            }else{
            $this->error($videos->getError());}
    }
  
    public function MyUpload(){
    $upload = new \Think\Upload();// 实例化上传类
    $upload->maxSize   =     3145728 ;// 设置附件上传大小
    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
    $upload->rootPath  =     './Public/Uploads/memberphoto/'; // 设置附件上传根目录
    $upload->autoSub   = false;//关闭子目录，默认ture
    //$info=$upload->uploadOne($_FILES['file']);  //上传文件

    //$upload->savePath  =     ''; // 设置附件上传（子）目录
    $upload->savename = 'time';

    $info   =   $upload->upload();  // 上传文件 
    //$dump(info);
    if(!$info) {        $this->error($upload->getError());    }
    else{return $info;}
    
    // else{        $this->success('上传成功！');    }  


    } //MyUpload end  
}